// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   AnnotationAttributesReadingVisitor.java

package org.springframework.core.type.classreading;

import java.lang.annotation.Annotation;
import java.lang.reflect.Modifier;
import java.util.*;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.MultiValueMap;
import org.springframework.util.ObjectUtils;

// Referenced classes of package org.springframework.core.type.classreading:
//			RecursiveAnnotationAttributesVisitor

final class AnnotationAttributesReadingVisitor extends RecursiveAnnotationAttributesVisitor
{

	private final String annotationType;
	private final MultiValueMap attributesMap;
	private final Map metaAnnotationMap;

	public AnnotationAttributesReadingVisitor(String annotationType, MultiValueMap attributesMap, Map metaAnnotationMap, ClassLoader classLoader)
	{
		super(annotationType, new AnnotationAttributes(), classLoader);
		this.annotationType = annotationType;
		this.attributesMap = attributesMap;
		this.metaAnnotationMap = metaAnnotationMap;
	}

	public void doVisitEnd(Class annotationClass)
	{
		super.doVisitEnd(annotationClass);
		List attributes = (List)attributesMap.get(annotationType);
		if (attributes == null)
			attributesMap.add(annotationType, this.attributes);
		else
			attributes.add(0, this.attributes);
		Set metaAnnotationTypeNames = new LinkedHashSet();
		Annotation metaAnnotations[] = AnnotationUtils.getAnnotations(annotationClass);
		if (!ObjectUtils.isEmpty(metaAnnotations))
		{
			Annotation aannotation[] = metaAnnotations;
			int i = aannotation.length;
			for (int j = 0; j < i; j++)
			{
				Annotation metaAnnotation = aannotation[j];
				if (!AnnotationUtils.isInJavaLangAnnotationPackage(metaAnnotation))
					recursivelyCollectMetaAnnotations(metaAnnotationTypeNames, metaAnnotation);
			}

		}
		if (metaAnnotationMap != null)
			metaAnnotationMap.put(annotationClass.getName(), metaAnnotationTypeNames);
	}

	private void recursivelyCollectMetaAnnotations(Set visited, Annotation annotation)
	{
		String annotationName = annotation.annotationType().getName();
		if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotation) && visited.add(annotationName) && Modifier.isPublic(annotation.annotationType().getModifiers()))
		{
			attributesMap.add(annotationName, AnnotationUtils.getAnnotationAttributes(annotation, false, true));
			Annotation aannotation[] = annotation.annotationType().getAnnotations();
			int i = aannotation.length;
			for (int j = 0; j < i; j++)
			{
				Annotation metaMetaAnnotation = aannotation[j];
				recursivelyCollectMetaAnnotations(visited, metaMetaAnnotation);
			}

		}
	}
}
